﻿using DevExpress.Mvvm;
using DotNetExtensions.AspNet.DevExpress.MVVM.ViewModels;
using Habi.Solver.Common;
using Habi.Solver.Models;
using Habi.Solver.Models.Meta;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Habi.Solver.ViewModels.Meta
{
    public class RegsitViewModel : SingleObjectViewModel<UserModel, string>
    {

        public virtual IList<DepartmentModel> Departments { get; set; }

        public virtual string Name { get; set; }
        public virtual string PhoneNumber { get; set; }
        public virtual string Email { get; set; }
        public virtual string Password { get; set; }
        public virtual string Password2 { get; set; }
        public virtual long DepartmentId { get; set; }

        public override bool BeforeClose(out string message)
        {
            message = "If you close, you cannot save this data."; return false;
        }

        public override void Readying()
        {
            Departments = new List<DepartmentModel>()
            {
                new DepartmentModel() { Id = 1, Name = "Habi.tv", Code = "" },
                new DepartmentModel() { Id = 2, Name = "Product", Code = "", ParentId = 1 },
                new DepartmentModel() { Id = 3, Name = "Design", Code = "", ParentId = 1 },
                new DepartmentModel() { Id = 4, Name = "Plan", Code = "", ParentId = 2 },
            };

            DepartmentId = 1;
        }

        public void Regist()
        {
            Console.WriteLine(DepartmentId);
            if (Validate())
            {
                //var result = HttpRequestService.Post<LoginModel>("https://localhost:44386/api/User/Regist", new RegistModel
                //{
                //    DepartmentId = DepartmentId,
                //    Email = Email,
                //    Host = AppEnvironment.Default.IPAddress,
                //    Mac = AppEnvironment.Default.Mac,
                //    Name = Name,
                //    Password = Password,
                //    PhoneNumber = PhoneNumber
                //});

                //if (result.Code != 200)
                //{
                //    MessageService.Warning(result.Msg);
                //}
                //else
                //{
                //    AppEnvironment.Default.User.Update(result.Data.Id, result.Data.Name, result.Data.Token);
                //    Messenger.Default.Send(AppEnvironment.Default.User);
                //    SilenceClose();
                //}
            }
        }
    }
}
